package com.mebs.edi.datalayer.jpa;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.mebs.edi.datalayer.CountryDao;
import com.mebs.model.Country;

public class JpaCountryDao extends JpaGenericDao implements CountryDao {

	public Country getCountry(String countryName) {
		EntityManager em = getEntityManager();
		
		TypedQuery<Country> query = em
			.createQuery("from Country c where c.name = :countryName", Country.class)
			.setParameter("countryName", countryName);
		Country country = query.getSingleResult();
		
		return country;
	}
	
	public Country getCountryByIso(String countryIso) {
		EntityManager em = getEntityManager();
		
		TypedQuery<Country> query = em
			.createQuery("from Country c where c.iso = :countryIso", Country.class)
			.setParameter("countryIso", countryIso);
		Country country = query.getSingleResult();
		
		return country;
	}

}
